

package TransportesMarroquin;

import com.mysql.jdbc.Blob; 
import java.awt.event.ActionEvent; 
import java.awt.event.KeyEvent; 
import javax.swing.JButton; 
import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.JPanel; 
import javax.swing.JScrollPane; 
import javax.swing.JTextArea; 
import javax.swing.JTextField;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.ResultSetMetaData;
import com.mysql.jdbc.Statement;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import java.awt.Toolkit;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;


public class PilotoSelect extends javax.swing.JFrame {
    Limitador limeda = new Limitador(2);
    Limitador limtel = new Limitador(8);
    Limitador limin = new Limitador(2);
    Limitador limcel = new Limitador(13);
    Limitador limi = new Limitador(20);
    Limitador limcd = new Limitador(11);
    Limitador limdir = new Limitador(50);
    Limitador limcesp = new Limitador(50);
    Limitador limnom = new Limitador(30);
    Limitador limcap = new Limitador(50);

int num;
 Blob img ;  // variables para la imagen
   byte[] imgData = null ;
   byte bit[] = null;

public PilotoSelect(int cod) {
        {
        initComponents();
        acep.setVisible(false);
        bcan.setVisible(false);
        num=cod;
        cd.setText(""+num);
        codigop.setText(""+num);
        ceda.setDocument(limeda);
        ctel.setDocument(limtel);
        cfam.setDocument(limin);
        clic.setDocument(limcel);
        cced.setDocument(limi);
        cd.setDocument(limcd);
        cdir.setDocument(limdir);
        cesp.setDocument(limcesp);
        cnom.setDocument(limnom);
        cape.setDocument(limcap);


        Connection conexion;
        try {

                // coneccion a la base de datos
        MysqlDataSource datasource= new MysqlDataSource();
        datasource.setUser("root");
        datasource.setPassword("");
        datasource.setDatabaseName("practicasp8");
        datasource.setServerName("localhost");

        conexion = (Connection) datasource.getConnection();


        Statement s = (Statement) conexion.createStatement();

 // query database
 ResultSet resultSet = s.executeQuery( "SELECT * FROM piloto where idpiloto="+num);
        ResultSetMetaData metaData = (ResultSetMetaData) resultSet.getMetaData();
         int numerodecolumnas = metaData.getColumnCount();


       while (resultSet.next()){
        for(int i=1;i<=numerodecolumnas;i++){
             switch(i){
                 // creo este switch par delimitar el nombre de los label ya establecidos :D
                 case 1:
                     cd.setText(""+resultSet.getObject(i));                    
                   break;
                 case 3:
                     cape.setText(""+resultSet.getObject(i));
                   break;
                 case 2:
                     cnom.setText(""+resultSet.getObject(i));
                   break;
                 case 4:
                     clic.setText(""+resultSet.getObject(i));
                   break;
                 case 5:
                     cced.setText(""+resultSet.getObject(i));
                     break;
                 case 6:
                      ctel.setText(""+resultSet.getObject(i));
                     break;
                 case 7:
                      cdir.setText(""+resultSet.getObject(i));
                     break;
                 case 8:
                      cesp.setText(""+resultSet.getObject(i));
                     break;
                 case 9:
                      cfam.setText(""+resultSet.getObject(i));
                     break;
                 case 10:
                     ceda.setText(""+resultSet.getObject(i));
                   break;
                 case 11:
                     ctip.setText(""+resultSet.getObject(i));
                   break;
                 case 12:
                     bit = resultSet.getBytes(i);
                     ImageIcon im = null;
                      if (bit != null) {
                          im= new ImageIcon(bit);

                     if(im.getIconWidth()>105 || im.getIconHeight()> 118){
                     ImageIcon imaescala = new ImageIcon(im.getImage().getScaledInstance(105, 118, 100));
                     prefoto.setIcon(imaescala);
                           }
                          else {
                             prefoto.setIcon(im);
                             }

                         } // fin del If
                    break;

             }

         }
       }

        } catch (SQLException ex) {
            Logger.getLogger(PilotoSelect.class.getName()).log(Level.SEVERE, null, ex);
        }

    } //fin del constructor
    }

    private PilotoSelect() {
      
    }

   
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        ceda = new javax.swing.JTextField();
        ctip = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        prefoto = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        clic = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        cnom = new javax.swing.JTextField();
        cd = new javax.swing.JTextField();
        breg = new javax.swing.JButton();
        cesp = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        cfam = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        cced = new javax.swing.JTextField();
        ctel = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        cape = new javax.swing.JTextField();
        bconf = new javax.swing.JButton();
        acep = new javax.swing.JButton();
        bcan = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        cdir = new javax.swing.JTextArea();
        jPanel1 = new javax.swing.JPanel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        codigop = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        ceda.setEnabled(false);
        ceda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cedaActionPerformed(evt);
            }
        });
        ceda.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                cedaKeyTyped(evt);
            }
        });

        ctip.setEnabled(false);
        ctip.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ctipActionPerformed(evt);
            }
        });
        ctip.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                ctipKeyTyped(evt);
            }
        });

        jLabel5.setText("Tipo Piloto");

        jLabel2.setText("Nombre");

        jLabel4.setText("Edad");

        prefoto.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Pilotos.gif"))); // NOI18N

        jLabel3.setText("Licencia");

        clic.setEnabled(false);
        clic.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clicActionPerformed(evt);
            }
        });

        jLabel1.setText("Codigo");

        cnom.setEnabled(false);
        cnom.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cnomActionPerformed(evt);
            }
        });
        cnom.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                cnomKeyTyped(evt);
            }
        });

        cd.setEnabled(false);
        cd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cdActionPerformed(evt);
            }
        });
        cd.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                cdKeyTyped(evt);
            }
        });

        breg.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/regresar.png"))); // NOI18N
        breg.setText("Regresar");
        breg.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bregActionPerformed(evt);
            }
        });

        cesp.setEnabled(false);
        cesp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cespActionPerformed(evt);
            }
        });
        cesp.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                cespKeyTyped(evt);
            }
        });

        jLabel12.setText("Nombre Esposa ");

        cfam.setEnabled(false);
        cfam.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cfamActionPerformed(evt);
            }
        });
        cfam.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                cfamKeyTyped(evt);
            }
        });

        jLabel11.setText("Integrantes en Familia ");

        jLabel9.setText("Dirección");

        cced.setEnabled(false);
        cced.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ccedActionPerformed(evt);
            }
        });
        cced.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                ccedKeyReleased(evt);
            }
        });

        ctel.setEnabled(false);
        ctel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ctelActionPerformed(evt);
            }
        });
        ctel.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                ctelKeyTyped(evt);
            }
        });

        jLabel8.setText("Telefono ");

        jLabel6.setText("Cedula ");

        jLabel7.setText("Apellido");

        cape.setEnabled(false);
        cape.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                capeActionPerformed(evt);
            }
        });
        cape.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                capeKeyTyped(evt);
            }
        });

        bconf.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/config.png"))); // NOI18N
        bconf.setText("Configurar");
        bconf.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bconfActionPerformed(evt);
            }
        });

        acep.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/aceptar.png"))); // NOI18N
        acep.setText("Aceptar");
        acep.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                acepActionPerformed(evt);
            }
        });

        bcan.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/cancelar.png"))); // NOI18N
        bcan.setText("Cancelar ");
        bcan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bcanActionPerformed(evt);
            }
        });

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/iviaje.png"))); // NOI18N
        jButton5.setText("Viajes ");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        cdir.setColumns(20);
        cdir.setLineWrap(true);
        cdir.setRows(5);
        cdir.setEnabled(false);
        jScrollPane2.setViewportView(cdir);

        jPanel1.setBackground(new java.awt.Color(143, 0, 0));

        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel13.setForeground(new java.awt.Color(255, 255, 255));
        jLabel13.setText("Piloto");

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel14.setForeground(new java.awt.Color(255, 255, 255));
        jLabel14.setText("Codigo");

        codigop.setFont(new java.awt.Font("Tahoma", 1, 18));
        codigop.setForeground(new java.awt.Color(255, 255, 255));
        codigop.setText("#");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel13)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 214, Short.MAX_VALUE)
                .addComponent(jLabel14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(codigop)
                .addGap(30, 30, 30))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(jLabel14)
                    .addComponent(codigop))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(39, 39, 39)
                        .addComponent(cd, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(77, 77, 77)
                        .addComponent(cnom, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addGap(77, 77, 77)
                        .addComponent(cape, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(77, 77, 77)
                        .addComponent(clic, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addGap(78, 78, 78)
                        .addComponent(cced, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addGap(69, 69, 69)
                        .addComponent(ctel, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addGap(65, 65, 65)
                        .addComponent(ctip, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(17, 17, 17)
                        .addComponent(prefoto, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(bconf)
                            .addComponent(jButton5)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(acep, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(bcan, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(breg)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel12)
                        .addGap(37, 37, 37)
                        .addComponent(cesp, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(90, 90, 90)
                        .addComponent(ceda, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel11)
                            .addComponent(jLabel9))
                        .addGap(4, 4, 4)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cfam, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(26, Short.MAX_VALUE))
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {acep, bcan, bconf, breg, jButton5});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {cape, cced, ceda, cesp, cfam, clic, cnom, ctel, ctip, jScrollPane2});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(jLabel1))
                    .addComponent(cd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(jLabel2))
                    .addComponent(cnom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(jLabel7))
                    .addComponent(cape, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(7, 7, 7)
                        .addComponent(jLabel3))
                    .addComponent(clic, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel6))
                    .addComponent(cced, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(ctel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addComponent(jLabel9))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(12, 12, 12)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(jLabel11))
                    .addComponent(cfam, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(jLabel12))
                    .addComponent(cesp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(jLabel4))
                    .addComponent(ceda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(jLabel5))
                    .addComponent(ctip, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bconf)
                        .addGap(11, 11, 11)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(acep)
                            .addComponent(bcan)))
                    .addComponent(prefoto))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(breg, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {acep, bcan, bconf, breg, jButton5});

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cedaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cedaActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_cedaActionPerformed

    private void ctipActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ctipActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_ctipActionPerformed

    private void clicActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clicActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_clicActionPerformed

    private void cnomActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cnomActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_cnomActionPerformed

    private void cdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cdActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_cdActionPerformed

    private void bregActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bregActionPerformed
        dispose();
        Piloto va;

        va = new Piloto();
        va.setVisible(true);
        va.setBounds(114, 107, Toolkit.getDefaultToolkit().getScreenSize().width-114, Toolkit.getDefaultToolkit().getScreenSize().height-107);

    }//GEN-LAST:event_bregActionPerformed

    private void cespActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cespActionPerformed

}//GEN-LAST:event_cespActionPerformed

    private void cfamActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cfamActionPerformed

}//GEN-LAST:event_cfamActionPerformed

    private void ccedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ccedActionPerformed

}//GEN-LAST:event_ccedActionPerformed

    private void ctelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ctelActionPerformed

}//GEN-LAST:event_ctelActionPerformed

    private void capeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_capeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_capeActionPerformed

    private void ccedKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_ccedKeyReleased
       if(evt.getKeyCode()==evt.VK_BACK_SPACE){
           System.out.println("pedos");
           
       }
    }//GEN-LAST:event_ccedKeyReleased

    private void bconfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bconfActionPerformed
        // obtener el dato de la llave primaria
   //HAbilito o desabilito los botones
    acep.setVisible(true);
    bcan.setVisible(true);
    bconf.setVisible(false);
    breg.setVisible(false);

    //Habilito Campos de Texto
    cape.setEnabled(false);
    cced.setEnabled(true);
    cd.setEnabled(false);
    cdir.setEnabled(true);
     ceda.setEnabled(true);
    cesp.setEnabled(true);
    cfam.setEnabled(true);
    clic.setEnabled(true);
    cnom.setEnabled(false);
    ctel.setEnabled(true);
    ctip.setEnabled(true);



}//GEN-LAST:event_bconfActionPerformed

    private void acepActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_acepActionPerformed
        //  opcion
        //UPDATE
        try {
            // coneccion
            //CONFIGURAR
            MysqlDataSource dataSource = new MysqlDataSource();
            dataSource.setUser("root");
            dataSource.setPassword("");
            dataSource.setDatabaseName("practicasp8");
            dataSource.setServerName("localhost");
            Connection conexion = (Connection) dataSource.getConnection();
            Statement instruccion = null;
            instruccion=(Statement) conexion.createStatement();
            // cambio los valores

            instruccion.executeUpdate("update piloto set idpiloto='"+cd.getText()+"' where idpiloto="+num);
            instruccion.executeUpdate("update piloto set nombre='"+cnom.getText()+"' where idpiloto="+num);
            instruccion.executeUpdate("update piloto set telefono='"+ctel.getText()+"' where idpiloto="+num);
            instruccion.executeUpdate("update piloto set apellido='"+cape.getText()+"' where idpiloto="+num);
            instruccion.executeUpdate("update piloto set cedula='"+cced.getText()+"' where idpiloto="+num);
            instruccion.executeUpdate("update piloto set direccion='"+cdir.getText()+"' where idpiloto="+num);
            instruccion.executeUpdate("update piloto set edad='"+ceda.getText()+"' where idpiloto="+num);
            instruccion.executeUpdate("update piloto set nomesposa='"+cesp.getText()+"' where idpiloto="+num);
            instruccion.executeUpdate("update piloto set numintegrantes='"+cfam.getText()+"' where idpiloto="+num);
            instruccion.executeUpdate("update piloto set licencia='"+clic.getText()+"' where idpiloto="+num);
            instruccion.executeUpdate("update piloto set tipopiloto='"+ctip.getText()+"' where idpiloto="+num);

            JOptionPane.showMessageDialog(rootPane, "Dato cambiado exitosamente" );

            acep.setVisible(false);
            bcan.setVisible(false);
            bconf.setVisible(true);
            breg.setVisible(true);
            
            cape.setEditable(false);
            cced.setEditable(false);
            cd.setEditable(false);
            cdir.setEditable(false);
            ceda.setEditable(false);
            cesp.setEditable(false);
            cfam.setEditable(false);
            clic.setEditable(false);
            cnom.setEditable(false);
            ctel.setEditable(false);
            ctip.setEditable(false);

        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(rootPane, "Se ha producido un error al tratar de cambiar el dato. " );
        }

    }//GEN-LAST:event_acepActionPerformed

    private void bcanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bcanActionPerformed
        breg.setVisible(true);  // muestro el regresar
        acep.setVisible(false);
        bcan.setVisible(false);
        bconf.setVisible(true);

        // REGRESO A OCULTAR LOS DATOS
            cape.setEnabled(false);
            cced.setEnabled(false);
            cd.setEnabled(false);
            cdir.setEnabled(false);
            ceda.setEnabled(false);
            cesp.setEnabled(false);
            cfam.setEnabled(false);
            clic.setEnabled(false);
            cnom.setEnabled(false);
            ctel.setEnabled(false);
            ctip.setEnabled(false);

    }//GEN-LAST:event_bcanActionPerformed

    private void cdKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cdKeyTyped
                 char c = evt.getKeyChar();
       if(!(Character.isDigit(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE){
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_cdKeyTyped

    private void ctelKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_ctelKeyTyped
                 char c = evt.getKeyChar();
       if(!(Character.isDigit(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE){
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_ctelKeyTyped

    private void cfamKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cfamKeyTyped
                char c = evt.getKeyChar();
       if(!(Character.isDigit(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE){
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_cfamKeyTyped

    private void cedaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cedaKeyTyped
               char c = evt.getKeyChar();
       if(!(Character.isDigit(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE){
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_cedaKeyTyped

    private void cnomKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cnomKeyTyped
            char c = evt.getKeyChar();
      if (!(Character.isLetter(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE) || ((c== KeyEvent.VK_SPACE)))) {
            getToolkit().beep();
            evt.consume();
}
    }//GEN-LAST:event_cnomKeyTyped

    private void capeKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_capeKeyTyped
          char c = evt.getKeyChar();
      if (!(Character.isLetter(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE) || ((c== KeyEvent.VK_SPACE)))) {
            getToolkit().beep();
            evt.consume();
}
    }//GEN-LAST:event_capeKeyTyped

    private void cespKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cespKeyTyped
           char c = evt.getKeyChar();
      if (!(Character.isLetter(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE) || ((c== KeyEvent.VK_SPACE)))) {
            getToolkit().beep();
            evt.consume();
}
    }//GEN-LAST:event_cespKeyTyped

    private void ctipKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_ctipKeyTyped
       char c = evt.getKeyChar();
       if(!(Character.isLetter(c))|| c== evt.VK_BACK_SPACE || c==evt.VK_DELETE || c== evt.VK_DEAD_TILDE)
       {
           getToolkit().beep();
           evt.consume();
       }
    }//GEN-LAST:event_ctipKeyTyped

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        dispose();
        
        
        Viaje vap = new Viaje("select * from viaje where id_piloto ="+num,"Piloto No.",num);
        vap.setVisible(true);
        
        vap.setBounds(114, 107, Toolkit.getDefaultToolkit().getScreenSize().width-114, Toolkit.getDefaultToolkit().getScreenSize().height-107);
}//GEN-LAST:event_jButton5ActionPerformed



    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new PilotoSelect().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton acep;
    private javax.swing.JButton bcan;
    private javax.swing.JButton bconf;
    private javax.swing.JButton breg;
    private javax.swing.JTextField cape;
    private javax.swing.JTextField cced;
    private javax.swing.JTextField cd;
    private javax.swing.JTextArea cdir;
    private javax.swing.JTextField ceda;
    private javax.swing.JTextField cesp;
    private javax.swing.JTextField cfam;
    private javax.swing.JTextField clic;
    private javax.swing.JTextField cnom;
    private javax.swing.JLabel codigop;
    private javax.swing.JTextField ctel;
    private javax.swing.JTextField ctip;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel prefoto;
    // End of variables declaration//GEN-END:variables

}
